/**
 * 
 */
package br.com.ctm.advogadope.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

import br.com.caelum.stella.bean.validation.CPF;
import br.com.framework.persistencia.model.AuditedEntity;

/**
 * @author Cleber
 * 
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="TIPO_CLIENTE")
@Table(name="CLIENTE")
@XmlRootElement
public abstract class Cliente extends AuditedEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Usuario usuario;
	
	private String nome;
	private String cpf;
	
	private Set<Processo> processos;

	/**
	 * 
	 */
	public Cliente() {
	}
	
	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_CLIENTE")
	@SequenceGenerator(name="SEQ_CLIENTE", sequenceName="SEQ_CLIENTE", allocationSize=1, initialValue=0)
	@Column(name = "ID_CLIENTE")
	public Long getId() {
		return super.getId();
	}

	/**
	 * @return the nome
	 */
	@Column(name = "NOME", length = 255, nullable = false)
	@Size(min = 1, max = 255, message = "{geral.campo.texto.tamanhoInvalido}")
	public String getNome() {
		return nome;
	}

	/**
	 * @param nome the nome to set
	 */
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**
	 * @return the cpf
	 */
	@Column(name = "CPF", length = 11, nullable = false)
	@CPF(formatted = false, message = "{geral.campo.cpf.invalido}")
	@NotNull(message = "{geral.campo.cpf.obrigatorio}")
	public String getCpf() {
		return cpf;
	}

	/**
	 * @param cpf the cpf to set
	 */
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}

	/**
	 * @return the usuario
	 */
	@OneToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
	@JoinColumn(name="ID_USUARIO")
	public Usuario getUsuario() {
		return usuario;
	}

	/**
	 * @param usuario the usuario to set
	 */
	public void setUsuario(Usuario usuario) {
		this.usuario = usuario;
	}

	/**
	 * @return the processos
	 */
	@ManyToMany(targetEntity=Processo.class)
	@JoinTable(name = "CLIENTE_PROCESSO", 
		joinColumns = @JoinColumn(name = "ID_CLIENTE", referencedColumnName = "ID_CLIENTE"), 
		inverseJoinColumns = @JoinColumn(name = "ID_PROCESSO", referencedColumnName = "ID_PROCESSO"))
	public Set<Processo> getProcessos() {
		return processos;
	}

	/**
	 * @param processos the processos to set
	 */
	public void setProcessos(Set<Processo> processos) {
		this.processos = processos;
	}


}
